﻿

#region Using Statements

// System References
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;

// XNA References
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

// Internal References
using Freeform.Framework.Graphics;

#endregion


namespace Freeform.Framework.Geometry
{
    /// <summary>
    /// Spatial properties define the position and orientation of a body in 2D space.
    /// </summary>
    public class SpatialProperties
    {

        #region Events

        /// <summary>
        /// This delegate represents the handler form for all Property Changed events.
        /// </summary>
        /// <param name="item">A reference to the spatial properties which triggered the event.</param>
        public delegate void PropertyChangedEventHandler(SpatialProperties properties);


        /// <summary>
        /// This event is fired when the position property is changed.
        /// </summary>
        public event PropertyChangedEventHandler PositionChanged;


        /// <summary>
        /// This event is fired when the size property is changed.
        /// </summary>
        public event PropertyChangedEventHandler SizeChanged;


        /// <summary>
        /// This event is fired when the direction property is changed.
        /// </summary>
        public event PropertyChangedEventHandler DirectionChanged;


        /// <summary>
        /// This event is fired when the motion handler is changed.
        /// </summary>
        public event PropertyChangedEventHandler MotionHandlerChanged;

        #endregion


        #region Members

        /// <summary>
        /// The position of the body in 2D space.
        /// </summary>
        public virtual Vector2 Position
        {
            get { return _Position; }
            set
            {
                if (_Position == value) return;
                _Position = value;
                if (PositionChanged != null)
                    PositionChanged(this);
            }
        }
        internal Vector2 _Position = Vector2.Zero;


        /// <summary>
        /// The orientation of the body in radians.
        /// </summary>
        public virtual Single Direction
        {
            get { return _Direction; }
            set
            {
                if (_Direction == value) return;
                _Direction = value;
                if (DirectionChanged != null)
                    DirectionChanged(this);
            }
        }
        internal Single _Direction = 0;


        /// <summary>
        /// Gets or sets the size of the body in world units.
        /// </summary>
        public virtual Vector2 Size
        {
            get { return _Size; }
            set
            {
                if (_Size == value) return;
                _Size = value;
                if (SizeChanged != null)
                    SizeChanged(this);
            }
        }
        internal Vector2 _Size = Vector2.One;


        /// <summary>
        /// Gets or sets the motion controller for this body.
        /// </summary>
        public virtual MotionController MotionController
        {
            get { return _MotionController; }
            set
            {
                if (_MotionController == value) return;
                _MotionController = value;
                if (MotionHandlerChanged != null)
                    MotionHandlerChanged(this);
            }
        }
        internal MotionController _MotionController = null;

        #endregion


        #region Init

        /// <summary>
        /// Creates a new set of spatial properties with default values.
        /// </summary>
        public SpatialProperties()
        {
            Position = Vector2.Zero;
            Direction = 0;
            Size = Vector2.One;
        }

        #endregion

    }
}
